/**
 * Created by yangh on 2016/09/03.
 */
var main = {};
var myScroll;
(function ($) {
    main.init = function () {
    	 document.addEventListener('touchmove', function (e) {
             e.preventDefault();
         }, false);
    };

    /**
     * @func move()
     * @desc 监听滚动条的位置，异步加载列表
     */
    function move() {
        if (this.y < main.max - 80) {
            $("#tip").hide();
            $("#loading").show();
            var maxId=$("#goodsShow li:last").val();
            var html = "";
            $.ajax({
            	type:"post",
        		async:false, 
	        	url:path+"/downSearch/Show?Id="+maxId,
        		success:function(resultjson){	
        			if('000' == resultjson.code){
        				var html = "";
        				if(resultjson.result.length>0){
        					for (var i = 0; i < resultjson.result.length; i++) {
        						html +='<li value="'+resultjson.result[i].goods.id+'"> <a href='+path+'/commodity/goodsinfo?goodsId='+resultjson.result[i].goods.id+'>\
        						<div class="goods-pic">\
        						<img src="'+resultjson.result[i].goods.picurl+'">\
        						</div>\
        						<h3>'+resultjson.result[i].goods.name+'</h3>\
        						<div class="score">\
        						<span class="star fa fa-star" ></span>\
        						<span class="star fa fa-star" ></span>\
        						<span class="star fa fa-star" ></span>\
        						<span class="star fa fa-star-half-o" ></span>\
        						<span class="star fa fa-star-o"></span>\
        						<span class="num">'+resultjson.result[i].score+'</span>\
        						</div>\
        						<div class="price">￥'+resultjson.result[i].goods.price+'元</div>\
        						</a>\
        						</li>';
        					}	
        					$(".goods").append(html);
        					  /* 评分 */
    		   				 score($(".scoreCon"));
    		   				myScroll.refresh();
        		            main.max = myScroll.maxScrollY;
        		            console.log(main.max);
        				}
        				
        			}
        		}
        	})
            $("#loading").hide();
            $("#tip").show();
        }
    }

    /**
     * @func main.scroll()
     * @desc 配置iscroll插件
     */
    main.scroll = function () {
        myScroll = new IScroll(".detail", {probeType: 3, mouseWheel: true, click: true, preventDefault: false});

        main.max = myScroll.maxScrollY;
        /*console.log(main.max);*/

        myScroll.on("scroll", move);
    }
})(jQuery);

main.init();